#include "eeprom.h"
#include "stm32l1xx.h"
#include "stm32l1xx_hal_flash_ex.h" 

//字节写
void FLASHEx_EEPROM_WRITE(uint16_t Address, uint8_t *Data, uint8_t len)
{
	uint8_t i;

	HAL_FLASHEx_DATAEEPROM_Unlock();
	//@ 此行代码用于解锁 eeprom ，否则第 1 个字节会发生写入错误
	HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE,DATA_EEPROM_START_ADDR+Address,*Data);
	for(i=0;i<len;i++)
	{
//		HAL_FLASHEx_DATAEEPROM_EnableFixedTimeProgram ();
		u8 status = HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE,DATA_EEPROM_START_ADDR+Address+i,*Data);
		if(status != HAL_OK)
		{
			printf("写入错误 \r\n");
		}
		Data++;
	}
//	HAL_FLASHEx_DATAEEPROM_DisableFixedTimeProgram();
	HAL_FLASHEx_DATAEEPROM_Lock();
}


//字节读
void FLASHEx_EEPROM_READ(uint16_t Addr,uint8_t *Buffer,uint16_t Length)
{
	uint8_t *wAddr;
	wAddr=(uint8_t *)(DATA_EEPROM_START_ADDR+Addr);
	while(Length--)
	{
		*Buffer++=*wAddr++;
	}	
}

